package cn.mn.ac.demo.controller;

import cn.mn.ac.demo.producer.ExampleProducer;
import io.gitee.hfl.rocketmq.msg.RocketMessage;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.apis.ClientException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author 何福临
 * @date 2022-08-29 20:11
 */
@Slf4j
@RestController
public class SendController {

    @Resource
    private ExampleProducer exampleProducer;

    @Value("${simple.topic}")
    private String topic;

    @Value("${simple.expression}")
    private String tag;

    @GetMapping("/send")
    public void send() throws ClientException {
        exampleProducer.sendMsg(RocketMessage.build("1", "2", "hello ons"), topic, tag);
    }

    @GetMapping("/send/async")
    public void sendAsync() {
        exampleProducer.sendMsgAsync(RocketMessage.build("1", "2", "hello ons"), topic, tag);
    }

}
